// pages/park/index/index.js
var call = require("../../../utils/request.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageStatus: false,
    listData: [],
    currentPark: {}, // 当前园区
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getParkList()  // 获取园区信息
  },
  // 获取园区信息
  getParkList () {
    call.httpData('GET','/api/index/parklist', {},
    res => {
      console.log(res,'获取园区信息')
      if(res.code == 1){
        let currentPark = res.data[0]
        this.setData({ listData: res.data,currentPark  })
        wx.setStorageSync('currentPark', currentPark);
      }else{
        wx.showToast({ icon: 'none',title: res.msg });
      }
      this.setData({ pageStatus: true })
    },function (err) {
      console.log(err)
    })
  },
  // 进入园区
  goPark () {
    wx.redirectTo({
      url: '/pages/home/index'
    })
  },
  // 切换园区
  switchPark (e){
    let { status } = e.currentTarget.dataset.obj
    console.log(status)
    switch (status){
      case 0:
      wx.showToast({ icon: 'none',title: '暂未开放' });
      break;
      case 1:
        wx.redirectTo({ url: '/pages/home/index' })
      break;
    }
    
  }
})